package com.ruoyi.web.controller.biz;

import java.util.List;

import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.biz.IBmMemberReportService;
import com.ruoyi.system.service.biz.IBmMemberService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.biz.BmMemberAmountRecord;
import com.ruoyi.system.service.biz.IBmMemberAmountRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员缴费记录Controller
 * 
 * @author ruoyi
 * @date 2022-11-18
 */
@Controller
@RequestMapping("/biz/record")
public class BmMemberAmountRecordController extends BaseController
{

    private String prefix = "biz/record";

    @Autowired
    private ISysUserService userService;

    @Autowired
    private IBmMemberService bmMemberService;

    @Autowired
    private IBmMemberAmountRecordService bmMemberAmountRecordService;

    @Autowired
    private IBmMemberReportService bmMemberReportService;

    @RequiresPermissions("biz:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询会员缴费记录列表
     */
    @RequiresPermissions("biz:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BmMemberAmountRecord bmMemberAmountRecord)
    {
        startPage();
        List<BmMemberAmountRecord> list = bmMemberAmountRecordService.selectBmMemberAmountRecordList(bmMemberAmountRecord);
        return getDataTable(list);
    }

    /**
     * 导出会员缴费记录列表
     */
    @RequiresPermissions("biz:record:export")
    @Log(title = "会员缴费记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BmMemberAmountRecord bmMemberAmountRecord)
    {
        List<BmMemberAmountRecord> list = bmMemberAmountRecordService.selectBmMemberAmountRecordList(bmMemberAmountRecord);
        ExcelUtil<BmMemberAmountRecord> util = new ExcelUtil<BmMemberAmountRecord>(BmMemberAmountRecord.class);
        return util.exportExcel(list, "会员缴费记录数据");
    }

    /**
     * 新增会员缴费记录
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("members", bmMemberService.selectAllBmMember());
        return prefix + "/add";
    }

    /**
     * 新增保存会员缴费记录
     */
    @RequiresPermissions("biz:record:add")
    @Log(title = "会员缴费记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BmMemberAmountRecord bmMemberAmountRecord)
    {
        for (int i=0;i<bmMemberAmountRecord.getMembers().length;i++){
            bmMemberAmountRecord.setAccount(bmMemberAmountRecord.getMembers()[i]);
            bmMemberAmountRecordService.insertBmMemberAmountRecord(bmMemberAmountRecord);
        }
        return AjaxResult.success("保存成功!");
    }

    /**
     * 修改会员缴费记录
     */
    @RequiresPermissions("biz:record:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BmMemberAmountRecord bmMemberAmountRecord = bmMemberAmountRecordService.selectBmMemberAmountRecordById(id);
        mmap.put("bmMemberAmountRecord", bmMemberAmountRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员缴费记录
     */
    @RequiresPermissions("biz:record:edit")
    @Log(title = "会员缴费记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BmMemberAmountRecord bmMemberAmountRecord)
    {
        return toAjax(bmMemberAmountRecordService.updateBmMemberAmountRecord(bmMemberAmountRecord));
    }

    /**
     * 删除会员缴费记录
     */
    @RequiresPermissions("biz:record:remove")
    @Log(title = "会员缴费记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bmMemberAmountRecordService.deleteBmMemberAmountRecordByIds(ids));
    }
}
